<?
/*----------------------------------------------------------------------
          (C) Bobtail-Bear 2006 	小飞熊新一代下载系统
          	代码编写：小飞熊	版权所有：小飞熊[L.F.Bear]
				官方网站/技术支持：http://www.lfbear.cn
------------------------------------------------------------------------
          (C) Bobtail-Bear 2006 	L.F.Bear's New Download Sysytem
          	Powered by L.F.Bear  Copyright L.F.Bear's Home(R)
               Official Web/Support：http://www.lfbear.cn
-----------------------------------------------------------------------*/
//本页脚本功能：前后台函数定义

//@error_reporting(E_ERROR | E_WARNING | E_PARSE);
require_once("include/config.base.php");
require_once("language/{$syslang}/function.php");

//定义读写函数
function readf($file_name) {
	$file0=@fopen($file_name,"r");
	@flock($file0,LOCK_SH);
	$read_data=@fread($file0,filesize($file_name));
	@fclose($file0);
	return $read_data;
}
function writef($file_name,$writeinfo,$method,$fuck=0) {
	if ($fuck!=0)$writeinfo=str_replace("|","",$writeinfo);//去掉危险字符
	$file1=@fopen($file_name,$method);
	flock($file1,LOCK_EX);
	$write_data=fwrite($file1,$writeinfo);
	fclose($file1);
	return;
}
//显示人员等级名称函数
function levelname_front($level,$type=1)
{
global $f_lang;
if ($type==1) require("include/userlevel.php");
else require("../include/userlevel.php");
$temp=$level_caption[$level];
if($temp=="") $temp=$f_lang[7];
return($temp);
}

//连接mysql(用于扩展功能)
function sql_connect($mysql_server,$mysql_user,$mysql_pass,$mysql_db)
{
if(@mysql_connect($mysql_server,$mysql_user,$mysql_pass) && @mysql_select_db($mysql_db))
return 1;
else
return 0;
}

//获取客户端ip
function getip()
{
global $f_lang;
if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]) 
{ 
$c_ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]; 
} 
elseif ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"]) 
{ 
$c_ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"]; 
}
elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"]) 
{ 
$c_ip = $HTTP_SERVER_VARS["REMOTE_ADDR"]; 
} 
elseif (getenv("HTTP_X_FORWARDED_FOR")) 
{ 
$c_ip = getenv("HTTP_X_FORWARDED_FOR"); 
} 
elseif (getenv("HTTP_CLIENT_IP")) 
{ 
$c_ip = getenv("HTTP_CLIENT_IP"); 
} 
elseif (getenv("REMOTE_ADDR"))
{ 
$c_ip = getenv("REMOTE_ADDR"); 
} 
else 
{ 
$c_ip = $f_lang[8]; 
}
return $c_ip;
}


//返回性别函数
function tellsex($sex)
{
global $f_lang;
switch($sex)
{
case 1:
	return $f_lang[9];
break;
case 2:
	return $f_lang[10];
break;
default:
	return $f_lang[11];
break;
}
}
function tellstate($key)
{
global $f_lang;
switch($key)
{
case "1":
return $f_lang[12];
break;
case "0":
return $f_lang[13];
break;
case "-1":
return $f_lang[14];
break;
default:
return $f_lang[15];
}
}
function tellwhether($key)
{
global $f_lang;
if($key=="y" || $key==1) return $f_lang[16];
else return $f_lang[17];
}
//返回带有格式的日期函数
function telldate($date)
{
global $f_lang;
$f_date[0]=substr($date,0,4);
$f_date[1]=substr($date,4,2);
$f_date[2]=substr($date,-2);
if($f_date[0]=="") return $f_lang[18];
else
return "$f_date[0]$f_lang[4]$f_date[1]$f_lang[5]$f_date[2]$f_lang[6]";
}

//返回带有格式的时间函数
function telltime($time)
{
global $f_lang;
$f_time[0]=substr($time,0,2);
$f_time[1]=substr($time,2,2);
$f_time[2]=substr($time,-2);
if($f_time[0]=="") return $f_lang[19];
else
return "$f_time[0]$f_lang[1]$f_time[1]$f_lang[2]$f_time[2]$f_lang[3]";
}
//页面左侧用户信息列表
function f_l_list($mode)
{
global $f_lang;
//模版路径声明
@require("include/template.php");
$imagepath="template/".$t_path."/images";
if($mode==1)
{
if($_SESSION[admin]=="y") $plus="<input type=\"button\" value=\"$f_lang[20]\" onClick=\"gotourl('admin/index.php');\" class=\"Button4\"/>";
$div="<form  id=\"login_ok\" action=\"index.php?action=login\" method=\"post\">
	    <table width=\"180\" height=\"125\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
          <tr>
            <td height=\"30\" colspan=\"2\"><img src=\"$imagepath/passport1.gif\" width=\"180\" height=\"30\" /></td>
          </tr>
          <tr>
            <td colspan=\"2\" bgcolor=\"#FFFFFF\"><table width=\"170\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
                <tr>
                <td height=\"20\" align=\"center\"><font color=#2381D7><b>$f_lang[21]</font></b></td>
              </tr>
    		 <tr>
                <td height=\"20\"><img src=\"$imagepath/itme0.gif\">$f_lang[22]$_SESSION[f_name]</td>
              </tr>
              <tr>
                <td height=\"20\"><img src=\"$imagepath/itme0.gif\">$f_lang[23]$_SESSION[f_point] $f_lang[59]</td>
              </tr>
              <tr>
                <td height=\"20\"><img src=\"$imagepath/itme0.gif\">$f_lang[24]$_SESSION[f_down] $f_lang[60]</td>
              </tr>
              <tr>
                <td height=\"20\" align=\"center\"><input type=\"button\" value=\"$f_lang[25]\" onClick=\"gotourl('user.php?action=see');\" class=\"Button2\"/>&nbsp;&nbsp;<input type=\"button\" value=\"$f_lang[26]\" onClick=\"gotourl('index.php?action=loginout');\" class=\"Button3\"/><br>$plus</td>
              </tr>
    <tr> <td height=\"50\" align=\"center\">$f_lang[27]<br>$_SESSION[lastlogin]</td></tr>
            </table></td>
          </tr>
        </table>
  </form>";
}
else if($mode==0)
{
if(!file_exists("include/bbs.php")) $regpage="reg.php";
else {@require("include/hack_bbs.php"); $regpage=$bbs_http."/".$bbs_reg;}

@require("include/config.base.php");
if($ccode=="y") $ccodeshow="<tr>
        <td height=\"20\" bgcolor=\"#FFFFFF\">$f_lang[28]</td>
        <td width=\"40\" valign=\"middle\" bgcolor=\"#FFFFFF\"><input name=\"code\" type=\"text\" id=\"code\" size=\"4\" maxlength=\"4\"></td>
        <td width=\"65\" valign=\"middle\" bgcolor=\"#FFFFFF\"><iframe id=\"codeshow\" name=\"codeshow\" marginheight=0 marginwidth=0 scrolling=no src=\"code.php\" height=\"20\" width=\"45\"></iframe></td>
      </tr>
      <tr>
        <td height=\"20\" colspan=\"3\" align=\"center\" bgcolor=\"#FFFFFF\"><a href=\"code.php\" target=\"codeshow\" title='$f_lang[29]'><font color='#FF3300'>$f_lang[30]</font></a></td>
      </tr>
      <tr>";

$div="<form  id=\"login\" action=\"index.php?action=login\" method=\"post\"><table width=\"180\" height=\"180\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
      <tr>
        <td height=\"30\" colspan=\"3\"><img src=\"$imagepath/passport.gif\" width=\"180\" height=\"30\" /></td>
      </tr>
      <tr>
        <td width=\"76\" height=\"20\" bgcolor=\"#FFFFFF\">$f_lang[31]</td>
        <td colspan=\"2\" bgcolor=\"#FFFFFF\"><input name=\"username\" type=\"text\" size=\"15\"></td>
      </tr>
      <tr>
        <td height=\"20\" bgcolor=\"#FFFFFF\">$f_lang[32]</td>
        <td colspan=\"2\" bgcolor=\"#FFFFFF\"><input name=\"userpass\" type=\"password\" size=\"15\"></td>
      </tr>".$ccodeshow."<td height=\"25\" colspan=\"3\" align=\"center\" bgcolor=\"#FFFFFF\"><input type=\"submit\" name=\"Submit\" value=\"$f_lang[33]\" class=\"Button2\" onClick=\"return checkform(this.form)\">
&nbsp;
<input type=\"reset\" name=\"Submit2\" value=\"$f_lang[34]\" class=\"Button3\" onClick=\"gotourl('$regpage')\"></td>
      </tr>
    </table>
</form>";
}
else
	$div="<table width=\"180\" height=\"125\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
      <tr>
        <td height=\"30\" colspan=\"2\"><img src=\"$imagepath/passport2.gif\" width=\"180\" height=\"30\" /></td>
      </tr>
      <tr>
        <td colspan=\"2\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFFF\"><table width=\"160\" height=\"95\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
            <tr>
              <td>$f_lang[35] </td>
            </tr>
          </table></td>
      </tr>
      
    </table>
";
return $div;
}

//显示人员等级名称函数
function levelname($level){
//session_start();
global $f_lang;
$loginmode=$_SESSION[loginmode];
require("include/userlevel.php");
if ($level_caption[$level]=="" && $loginmode!="mysql") 
{
	$msg_title=$f_lang[36];
	$msg_link="login.php";
	$msg=$f_lang[37];
	require("error.php");
	die;
	return(0);
}
else if ($loginmode=="mysql")
{
$_SESSION[level_name]=$f_lang[38];
return(1);
}
else
{
$_SESSION[level_name]=$level_caption[$level];
return(1) ;
}
}

function mimi()
{
$check_code=md5("r0a5n2d1");
$code_1=substr($check_code,6,6);
$code_2=substr($check_code,16,6);
return $code_1.$code_2;
}

//检查是否具有管理权限函数
function checklevel($level,$item){
global $f_lang;
$loginmode=$_SESSION[loginmode];
require("include/userlevel.php");
if ($level_caption[$level]=="" && $loginmode!="mysql") 
{
	$msg_title=$f_lang[36];
	$msg_link="login.php";
	$msg=$f_lang[37];
	require("error.php");
	die;
	return(0);
}
else if($loginmode=="mysql") return(1);
else {
switch($item){
case "system":
if ($level_system[$level]=="y") return(1);else return(0);
break;
case "soft":
if ($level_soft[$level]=="y") return(1);else return(0);
break;
case "news":
if ($level_news[$level]=="y") return(1);else return(0);
break;
case "upload":
if ($level_upload[$level]=="y") return(1);else return(0);
break;
case "user":
if ($level_user[$level]=="y") return(1);else return(0);
break;
case "advance":
if ($level_advance[$level]=="y") return(1);else return(0);
break;
default: return(0);
}}}

//记录日志函数
function weblog($action,$operate,$color,$login,$other)
{
global $f_lang;
if($action=="101"){$file="include/weblog_login.php";$action=$f_lang[39];}
else if($action=="102") {$file="include/weblog_operate.php";$action=$f_lang[40];}
else if($action=="0") {$file="../include/weblog_login.php";$action=$f_lang[41];}
else $file="../include/weblog_operate.php";
$begin="<? die(\"Forbidden Access!\");?>";
$c_ip = getip();
$c_date= date(Y).$f_lang[4].date(m).$f_lang[5].date(d).$f_lang[6];;
$c_time= date(H).$f_lang[1].date(i).$f_lang[2].date(s).$f_lang[3];
if (!file_exists($file))
writef($file,$begin,"w");

$info="\n"."$c_date|$c_time|$login|$c_ip|$action|$operate|$color|$other";
writef($file,$info,"a");
}

//去掉危险字符"|"函数
function ckchar($char){
$char=str_replace("|","",$char);
return $char;
}
//返回分类名称函数
function showclassname($class,$subclass,$path=0)
{
global $classname;
if($path==1){
$classfile="../include/class.php";
$subclassfile="../include/subclass.php";
}
else
{
$classfile="include/class.php";
$subclassfile="include/subclass.php";
}
	$downlist1=file($classfile);
	$fcount1=count($downlist1);
	for ($i=0; $i<$fcount1; $i++) {
	$detail1=explode("|",$downlist1[$i]);
	if($detail1[0]==$class) $classname[0]=$detail1[1];
	}

	$downlist2=file($subclassfile);
	$fcount2=count($downlist2);
	for ($j=0; $j<$fcount2; $j++) {
	$detail2=explode("|",$downlist2[$j]);
	if($detail2[0]==$subclass) $classname[1]=$detail2[2];
	}
return $classname;
}

//核对下载信息函数（暂无用）
function check_down($id)
{
$check_pre="r0a5n2d1_".$id;
$check_info="403a9996de7d"."_".$id;
setcookie("$check_pre","$check_info",time()+300);
}
//判断演示地址还是预览图片
function choose_pre_dem($choose,$http)
{
global $f_lang;
//模版路径声明
@require("include/template.php");
$imagepath="template/".$t_path."/images";
global $pic_http;
if($choose==2 && $http!="") {$pic_http=$imagepath."/nopre.jpg"; return "$f_lang[42] <a href=$http target=\"_blank\">$f_lang[43]</a>";}
elseif($choose==1 && $http!="") {$pic_http=$http;return "$f_lang[44] <a href=$http target=\"_blank\">$f_lang[43]</a>";}
else {$pic_http=$imagepath."/nopic.jpg"; return $f_lang[45];}
}
//判断软件是否过期
function timeout($date1/*软件加入日期*/,$date2/*过期期限*/)
{
if ($date2=="0") return "-1";
else {
//	echo $date2."<br>".$date1."<br>";
$date3=date(Ymd);//目前日期
$y=0;$m=0;$d=0;//初始化
if($date2<30) $d=$date2;
else {$m=floor($date2/30); $d=$date2%30;}
if($m<12) $y=0;
else{$y=floor($m/12); $m=$m%12;}
$newdate=$date1+$y*10000+$m*100+$d;

//echo "中间处理数据".$newdate."<br>";
if(substr($newdate,-2)>30) 
{$n_d=substr($newdate,-2)-30;$n_m=substr($newdate,4,2)+1;}
else {$n_d=substr($newdate,-2);$n_m=substr($newdate,4,2);}
if($n_m>12) {$n_m=$n_m-12;$n_y=substr($newdate,0,4)+1;}
else $n_y=substr($newdate,0,4);
//echo "最后处理数据 日是 $n_d 月是 $n_m 年是 $n_y";
$newdate=$n_y*10000+$n_m*100+$n_d;

//echo $newdate."<br>".$date3;
if ((int)$newdate<(int)$date3) return 0;
else {
$otherdate=($n_y-date(Y))*365+($n_m-date(m))*30+$n_d-date(d);
return $otherdate;
}
}
}

//处理view页广告代码
function view_ad($code,$position=1)
{
if($code==0)
{
require("include/config.index.php");
if($position==1) return $ad_code_1;
else return $ad_code_2;
}
else
return $code;
}

//登陆加分函数

function logingood($username,$point,$path_user)
{
$user_info789=readf($path_user."/".$username.".php");
$user_info999=explode("|",$user_info789);
$user_info999[4]+=$point;
$user_info789=$user_info999[0]."|".$user_info999[1]."|".$user_info999[2]."|".$user_info999[3]."|".$user_info999[4]."|".$user_info999[5];
writef($path_user."/".$username.".php",$user_info789,"w");
return 1;
}

//登陆日志
function loginlog($username,$path_user)
{
$c_ip=getip();
require("include/config.inc.php");

if(!file_exists($path_user."/".$username.".log"))
writef($path_user."/".$username.".log","1|".date(Ymd)."|".date(His)."|".$c_ip,"w");
else 
{
$log_note=readf($path_user."/".$username.".log");
$log_note=explode("|",$log_note);
if($log_note[1]==date(Ymd)) 
{
$log_note[0]++;
writef($path_user."/".$username.".log",$log_note[0]."|".date(Ymd)."|".date(His)."|".$c_ip,"w");
}
else writef($path_user."/".$username.".log","1|".date(Ymd)."|".date(Hij)."|".$c_ip,"w");
}
return 1;
}

//下载扣分
function download($username,$value,$path_user)
{
global $f_lang;
if(file_exists("include/bbs.php"))
{
	if(!file_exists("include/hack_bbs.php")) 
	{
	$fb_title1=$f_lang[46];
	$fb_title2=$f_lang[47];
	$fb_msg="hack_bbs.php $f_lang[48]";
	require("feedback.php");	
	}
	require("include/hack_bbs.php");
	if(!sql_connect($mysql_server,$mysql_user,$mysql_pass,$mysql_db))
	{
	$fb_title1=$f_lang[46];
	$fb_title2=$f_lang[49];
	$fb_msg=$f_lang[50];
	require("feedback.php");	
	}
	$newvalue=$_SESSION[f_point]-$value;
	$sql1=mysql_query("SELECT * FROM `$bbs_table1` where `$bbs_name` = '$username'");
	$sqlinfo1=mysql_fetch_array($sql1);
	$uid=$sqlinfo1[$bbs_m];
	$sql=mysql_query("UPDATE `$bbs_table2` SET `$bbs_jf` = '$newvalue' WHERE `$bbs_table2`.`$bbs_m` = '$uid' ");
	if($sql)
	{
	$_SESSION[f_point]-=$value;
	return 1;
	}
	else 
	{
	$fb_title1=$f_lang[46];
	$fb_title2=$f_lang[51];
	$fb_msg=$f_lang[52];
	require("feedback.php");	
	}
}
else
{
	$now_info=readf($path_user."/".$username.".php");
	$now_info=explode("|",$now_info);
	$now_info[4]-=$value;
	$now_info=$now_info[0]."|".$now_info[1]."|".$now_info[2]."|".$now_info[3]."|".$now_info[4]."|".$now_info[5];
	writef($path_user."/".$username.".php",$now_info,"w");
	$_SESSION[f_point]-=$value;
	return 1;
}
}

//判断下载权限
function ispopedom($popedom)
{
global $f_lang;
if($popedom<=0) return 1;
else {
if($_SESSION[f_down]>=$popedom) return 1;
elseif($_SESSION[f_login]!="yes" || $_COOKIE[l_state]!="ok") 
{
	$e_title=$f_lang[61];
	$e_msg=$f_lang[53];
	$e_link="$f_lang[66]";
	require("error.php");
}
else
{
	$e_title=$f_lang[61];
	$e_msg=$f_lang[54];
	$e_link="$f_lang[66]";
	require("error.php");
}
}
}

//记录下载次数
function downplus($id,$path_soft)
{
file_exists($path_soft."/click/".$id.".dnt") ? $down_time=readf($path_soft."/click/".$id.".dnt")+1 : $down_time=1;
writef($path_soft."/click/".$id.".dnt",$down_time,"w");
return 1;
}

//首页字符截取函数(来自internet)
//cut_str(字符串, 截取长度(汉字), 开始长度, 编码);
function cut_str($string, $sublen, $start = 0, $code = 'UTF-8')
{
if($code == 'UTF-8')
{
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
preg_match_all($pa, $string, $t_string);

if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen))."...";
return join('', array_slice($t_string[0], $start, $sublen));
}
else
{
$start = $start*2;
$sublen = $sublen*2;
$strlen = strlen($string);
$tmpstr = '';
for($i=0; $i<$strlen; $i++)
{
if($i>=$start && $i<($start+$sublen))
{
if(ord(substr($string, $i, 1))>129) $tmpstr.= substr($string, $i, 2);
else $tmpstr.= substr($string, $i, 1);
} 
if(ord(substr($string, $i, 1))>129) $i++;
}
if(strlen($tmpstr)<$strlen ) $tmpstr.= "..";
return $tmpstr;
}
}

//刷新软件列表
function freshsoftlist($softnumber,$path_soft,$type=1)
{
$type==1 ? $pathper="../" : $pathper="";
$total=readf($pathper.$path_soft."/number");
$fn=ceil($softnumber/100);
$b_num=($fn-1)*100+1;
$fn*100<$total ? $e_num=$fn*100 : $e_num=$total;
unset($list_info);
for($i=$b_num;$i<=$e_num;$i++)
{
unset($temp);unset($tempy);
$temp=readf($pathper.$path_soft."/".$i.".php");
$tempy=readf($pathper.$path_soft."/".$i.".kwd");
$temp=explode("|",$temp);
$tempy=explode("|",$tempy);
if(!file_exists($pathper.$path_soft."/".$i.".dat")) $list_info.="\n";
else
$list_info.=$i."|".$temp[1]."|".$temp[3]."|".$temp[2]."|".$temp[6]."|".$temp[7]."|".$temp[5]."|".$tempy[1]."\n";

}
writef($pathper."cache/soft_list_".$fn.".php",$list_info,"w");
}

//前台登陆
function f_login($name,$pass)
{
global $f_lang;
$loginok=1;
require("include/config.inc.php");
if(file_exists("include/bbs.php"))
{
@require("include/hack_bbs.php");
if(!sql_connect($mysql_server,$mysql_user,$mysql_pass,$mysql_db))
{
$fb_title1=$f_lang[46];
$fb_title2=$f_lang[49];
$fb_msg=$f_lang[50];
require("feedback.php");
}
$pass=md5($pass);

$sql1=mysql_query("SELECT * FROM `$bbs_table1` where `$bbs_name` = '$name' and `$bbs_pass` = '$pass' ");
$sqlinfo1=mysql_fetch_array($sql1);
$uid=$sqlinfo1[$bbs_m];
$sql2=mysql_query("SELECT * FROM `$bbs_table2` where `$bbs_m` = '$uid' ");
$sqlinfo=mysql_fetch_array($sql2);

if($bbs_table==1) {$cgx=$sqlinfo1[$bbs_cg1]; }
else {$cgx=$sqlinfo[$bbs_cg1];}

if($sqlinfo1)
{
$user_info[3]=0;
switch($bbs_cg3)
{
case 1:
if ($cgx>=$bbs_cg2) $user_info[3]=1;
break;
case 2:
if ($cgx<=$bbs_cg2) $user_info[3]=1;
break;
case 3:
default:
if ($cgx==$bbs_cg2) $user_info[3]=1;
break;
}
$user_info[4]=$sqlinfo[$bbs_jf];
$user_info[5]=$sqlinfo[$bbs_qx];
}
else 
{
$loginok=0;
$fb_title1=$f_lang[46];
$fb_title2=$f_lang[55];
$fb_msg=$f_lang[56];
require("feedback.php");
}
}
else
{
if(!file_exists($path_user."/".$name.".php"))
{
$loginok=0;
$fb_title1=$f_lang[46];
$fb_title2=$f_lang[55];
$fb_msg=$f_lang[57];
require("feedback.php");
}
else
{
$user_info_t=readf($path_user."/".$name.".php");
$user_info=explode("|",$user_info_t);
}
if(md5($pass)!=$user_info[2])
{
$loginok=0;
$fb_title1=$f_lang[46];
$fb_title2=$f_lang[55];
$fb_msg=$f_lang[58];
require("feedback.php");
}
}
if ($loginok==1)
{
	$lastlogin=readf($path_user."/".$name.".log");
	$lastlogin=explode("|",$lastlogin);
	$_SESSION[lastlogin]=telldate($lastlogin[1]).telltime($lastlogin[2]).$lastlogin[3];
	loginlog($name,$path_user);
    setcookie("l_state","ok",time()+3600);
	$_SESSION[f_login]="yes";
	$_SESSION[f_name]=$name;
	$_SESSION[f_point]=$user_info[4];
	$_SESSION[f_down]=$user_info[5];
    if($user_info[3]==1) $_SESSION[admin]="y";
}
}

//后台登陆

function b_login($login_name,$psw,$mode=1)
{
	global $f_lang;
	$loginadmin=0;
	$psw=md5($psw);
	if($mode==2)
	{
	@require("include/hack_bbs.php");
	if(!sql_connect($mysql_server,$mysql_user,$mysql_pass,$mysql_db))
	{
	$msg_title=$f_lang[49];
	$msg_link="login.php";
	$msg=$f_lang[50];
	require("error.php");
	die();
	}
	$sql1=mysql_query("SELECT * FROM `$bbs_table1` where `$bbs_name` = '$login_name' and  `$bbs_pass` = '$psw' ");
	$sqlinfo1=mysql_fetch_array($sql1);
	$uid=$sqlinfo1[$bbs_m];
	$sql2=mysql_query("SELECT * FROM `$bbs_table2` where `$bbs_m` = '$uid' ");
	$sqlinfo=mysql_fetch_array($sql2);
	if($bbs_table==1) {$cgx=$sqlinfo1[$bbs_cg1]; $s_ok=$sqlinfo1;}
	else {$cgx=$sqlinfo[$bbs_cg1];$s_ok=$sqlinfo;}
	
	if($s_ok)
	{
	$user_level=-2;
	switch($bbs_cg3)
	{
	case 1:
	if ($cgx>=$bbs_cg2) $user_level=-1;
	break;
	case 2:
	if ($cgx<=$bbs_cg2) $user_level=-1;
	break;
	case 3:
	default:
	if ($cgx==$bbs_cg2) $user_level=-1;
	break;
	}
	$_SESSION[level]=1;
	$_SESSION[loginmode]="mysql";
	$loginadmin=1;
	$data[1]=$login_name;
	$data[4]=$sqlinfo[$bbs_jf];
	$data[5]=$sqlinfo[$bbs_qx];
	}
	}
	if($mode==1)
	{
	require("include/config.inc.php");
	$tmp=readf("../".$path_user."/".$login_name.".php");
	$data=explode("|",$tmp);
	$user_level=$data[3];
	if ($login_name==$data[1] && $psw==$data[2]) $loginadmin=1;
	}
	if ($loginadmin==1)
	{
	setcookie("status","login",time() + $_POST[logintime]);
	setcookie("yourname",$data[1],time() + $_POST[logintime]);
	$_SESSION[login]="yes";
	$_SESSION[level]=$data[3];
	$_SESSION[point]=$data[4];
	$_SESSION[down]=$data[5];
	return $user_level;
	}
	else return 0;
	
}

?>